package dal.object;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.image.BufferedImage;

public class MapObject {
	protected BufferedImage img;
	protected Point location;
	protected Graphics2D grap;
	
	/**
	 * @param g
	 * 	the drawer's graphics
	 */
	public void drawObject(Graphics g){
		g.drawImage(img, location.x, location.y, null);
		grap = (Graphics2D) g;
	}

	/**
	 * @return
	 * 	the object's image
	 */
	public BufferedImage getImage() {
		return img;
	}
	
	/**
	 * repaints the object without clearing first
	 */
	public void repaint(){
		if(grap != null){
			grap.drawImage(img, location.x, location.y, null);
		}
	}
	
	/**
	 * @param location
	 * 	sets the object position
	 */
	public void setLocation(Point location){
		this.location = new Point(location.x, location.y);
	}
	
	/**
	 * @return
	 * 	the object position
	 */
	public Point getLocation(){
		return this.location;
	}
	
	public Dimension getSize(){
		return new Dimension(img.getWidth(), img.getHeight());
	}
	
	/**
	 * returns the name of the object's class as a String
	 */
	public String toString(){
		return this.getClass().getSimpleName();
	}

	/**
	 * @param img
	 * 	replaces this object image
	 */
	public void setImage(BufferedImage img) {
		this.img = img;
		repaint();
	}
}
